<?php
include("header.php");

if(isset($_SESSION['userid'])){
	if($_SESSION['type']=="teacher"){
		header("Location: http://$host$uri/teacher.php");
	}
	elseif($_SESSION['type']=="admin"){
		header("Location: http://$host$uri/admin.php");
	}
	elseif($_SESSION['type']=="parent"){
		header("Location: http://$host$uri/parent.php");
	}

}

?>
<script>
$(document).ready(function(){

	$("#submit").click(function(){
		var username = $("#username").val();
		var password = $("#password").val();
		$.post(
			"login.php",
			{username:username,password:password},
			function(data){
				if(data=="parent"){
					window.location = "parent.php";
				}
				else if(data=="teacher"){
					window.location = "teacher.php";
				}
				else if(data=="admin"){
					window.location = "admin.php";
				}
				else if(data=="wrong"){
					$(".notice").html("Invalid Username or Password");
				}
			}	
		);	
	});

});
</script> 
<div class="login">
<table>
<tr>
	<td colspan="2">Please Login</td>
</tr>
<tr>
	<td>Username</td><td><input type="text" name="username" id="username"></td>
</tr>
<tr>
	<td>Password</td><td><input type="password" name="password" id="password"></td>
</tr>
<tr>
	<td colspan="2"><input type="button" id="submit" value="Login"></td>
</tr>
<tr>
	<td colspan="2" class="notice"><?php echo $_GET['notice'] ?></td>
</tr>
</table>
</div>